<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Column;
use addons\BuilderPlus\components\Search;
use addons\BuilderPlus\facade\Table;

class UserNotify extends Base
{
    public function getOptions(): array
    {
        return [
            'pk' => 'id',
            'model' => \app\common\model\UserNotify::class,
            'validate' => \app\admin\validate\UserNotify::class,
            'with' => ['user'],
            'append' => ['type_name', 'status_name'],
            'just' => false,
            'fast' => [
                'add' => 'user_notify/add'
            ]
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->setCheckbox(false)
            ->addColumns([
                ['id', 'ID', fn(Column $col) => $col->width(80)],
                ['uid', '相关会员', fn(Column $col) => $col->templet('#_userTpl')->minWidth(240)],
                ['type_name', '消息类型'],
                ['title', '标题'],
                ['content', '内容'],
                ['status_name', '状态'],
                ['create_time', '通知时间', fn(Column $col) => $col->width(150)]
            ])
            ->addTopButtons(['add'])
            ->addRightButtons(['delete'], 100)
            ->addSearch([
                ['create_time', '通知时间', fn(Search $search) => $search->type('date')],
                ['uid', '会员编号/昵称/手机号', fn(Search $search) => $search
                    ->relation('\app\common\model\User', 'code|nickname|mobile,id')
                    ->condition('Like')],
                ['type_id', '消息类型', fn(Search $search) => $search->type('select')
                    ->optionValue(getNotifyType())]
            ])
            ->fetch();
    }
}